package com.example.demo.trade.controller;

import java.time.LocalDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.example.demo.trade.service.TradeService;

@RestController
@RefreshScope
@RequestMapping("/trade")
public class TradeController {

    @Autowired
    private TradeService tradeService;

    @RequestMapping("/test")
    //    @SentinelResource(value = "TRADE_TEST_CONTROLLER", blockHandler = "testControllerBlock")
    @SentinelResource(value = "TRADE_TEST_CONTROLLER", blockHandler = "testControllerBlock")
    public String test() {
        String result = tradeService.test();
        return result;
    }

    @RequestMapping("/list")
    public String list() {
        return "list. time: " + LocalDateTime.now();
    }

    private String testControllerBlock(BlockException e) {
        return "controller 限流, time: " + LocalDateTime.now();
    }

}
